/* Copyright  2009-2010
   @Author
   Richard Changde Yin            e-mail yinchangde@hotmail.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 *  @filename:key_part_spec.h
 */


#ifndef __KEY_PART_SPEC_H__
#define __KEY_PART_SPEC_H__

#include <sql_alloc.h>

class Item;
typedef struct st_mem_root MEM_ROOT;

class Key_part_spec :public Sql_alloc {
public:
  LEX_STRING field_name;
  uint32_t length;
  Key_part_spec(const LEX_STRING &name, uint32_t len)
                : field_name(name), length(len)
                {}
  Key_part_spec(const char *name, const size_t name_len, uint32_t len)
                : length(len)
    { field_name.str= (char *)name; field_name.length= name_len; }
  bool operator==(const Key_part_spec& other) const;
  /**
    Construct a copy of this Key_part_spec. field_name is copied
    by-pointer as it is known to never change. At the same time
    'length' may be reset in sql_prepare_create_table, and this
    is why we supply it with a copy.

    @return If out of memory, 0 is returned and an error is set in
    Session.
  */
  inline Key_part_spec *clone(MEM_ROOT *mem_root) const
                   { return new (mem_root) Key_part_spec(*this); }
};

#endif /* __KEY_PART_SPEC_H__ */
